var ctx = localStorage.getItem("ctx");
var wholeprovinceId = '';
var wholecityId = '';
var wholecompanyId = '';
var dvName = '';
var driverSearchDate = '';
var table = '';
$(function() {
		
	juicer.set({
	    'tag::operationOpen': '-~',
	    'tag::operationClose': '+',
	    'tag::interpolateOpen': '#-',
	    'tag::interpolateClose': '+',
	    'tag::noneencodeOpen': '##-',
	    'tag::noneencodeClose': '+',
	    'tag::commentOpen': '-*',
	    'tag::commentClose': '+'
	});

	var newspecialAuthInfoId = '';
	var newsuId = '';
	var newuserId = '';
	var newuvId = '';
	var newvaId = '';
	
	
	
	var wholeautype = '';
	
	var newimg1 = '';
	var newimg2 = '';
	var newimg3 = '';
	var newimg4 = '';
	var newimg5 = '';
	var newimg6 = '';
	var newimg7 = '';
	var newimg8 = '';
	
	var isAdmin = localStorage.getItem('isAdmin');
	console.log(isAdmin);
	if(isAdmin == 'false') {
		$(".isAdminProvince").hide();
		$(".isAdminCity").hide();
		$(".isAdminCompany").hide();
		//非超级管理员获取公司列表
		getCompanyByOtherUser();
	}
	if(isAdmin == 'true') {
		$(".isOtherUserCompany").hide();
	}
	//获取表格
	driverTable(wholeprovinceId,wholecityId,wholecompanyId,2,dvName,driverSearchDate);
		
		
	//获取省份
    getProvince();
    getCity('');
    getCompany('','');
    //品牌和车型初始化
    getCarBrand();
    getCarModel('33');
    
    editgetProvince();
//    editgetCity();
	editgetCompany();
    //根据选取的省份获取城市和公司
    $(".provinceEditSelect").on("change", function(){
    	var provinceId = $(this).attr("value");
    	editgetCity(provinceId);
    	editgetCompany(provinceId,'');
    });
    
    //根据省份和城市获取公司
    $(".cityEditSelect").on("change", function() {   	
    	var provinceId = $(".provinceEditSelect").find("option:selected").attr("value");
    	var cityId = $(this).attr("value");
    	editgetCompany(provinceId,cityId);
    });
    
    
    //根据选取的省份获取城市和公司
    $(".provinceSelect").on("change", function(){
    	var provinceId = $(this).attr("value");
    	getCity(provinceId);
    	getCompany(provinceId,'');
    });
    
    //根据省份和城市获取公司
    $(".citySelect").on("change", function() {   	
    	var provinceId = $(".provinceSelect").find("option:selected").attr("value");
    	var cityId = $(this).attr("value");
    	getCompany(provinceId,cityId);
    });
    
    //根据车辆品牌查询车辆类型
    $(".carBrandSelect").on("change", function(){
    	var carBrandId = $(this).attr("value");
    	getCarModel(carBrandId);
    });
    
    //查询
    $(".btn-search").on("click", function() {
    	wholeprovinceId = $(".provinceSelect").find("option:selected").attr("value");
    	wholecityId = $(".citySelect").find("option:selected").attr("value");
    	//判断是否是超级管理员
    	if(isAdmin == 'false') {
    		wholecompanyId = $(".otherUserCompanySelect").find("option:selected").attr("value");
    	}
    	else {
    		wholecompanyId = $(".companySelect").find("option:selected").attr("value");
    	}
    	
    	dvName = $(".searchdvname").val();
    	driverSearchDate = $(".driverSearchDate").val();
    	
    	table.destroy();
    	//查询获取表格
    	driverTable(wholeprovinceId,wholecityId,wholecompanyId,2,dvName,driverSearchDate);
    	
    	
    });
    
    
	
	
	
	//查看详情
	$(document).on( 'click', '.btn-detail', function () {
		
        var data = table.row( $(this).parents('tr') ).data();
        var userId = data.userId;
        $.ajax({
        	
        	type: 'POST',
    		url: ctx+'/driver/v1/dvdetail',
    		dataType: 'json',
    		data: {
    			suid: userId
    		},
    		success: function(data) {
    			console.log(data);
    			var vehicleLevelId = data.vehicleLevelId;
    			var authType = data.authType;
				//3:出租车  2:专车
				if(authType == 2) {
					$(".workLicenseNumberTh").hide();
					$(".workLicenseNumberTd").hide();
					$(".workLicenseImageDiv").hide();
					$(".workLicenseImageDiv").hide();
				}
				if(authType == 3) {
					$(".workLicenseNumberTh").show();
					$(".workLicenseNumberTd").show();
					$(".workLicenseNumberTd").html(data.workLicenseNumber);
					$(".workLicenseImageDiv").show();
					$(".workLicenseImage").attr("src", data.workLicenseImage);
				}
    			$(".provinceTd").html(data.provice_name);
    	        $(".cityTd").html(data.cityName);
    	        $(".companyTd").html(data.organizationName);
    	        $(".nameTd").html(data.trueName);
    	        if(vehicleLevelId == 1) {
    	        	$(".vehicleLevelTd").html("经济型");
    	        }
    	        else if(vehicleLevelId == 2) {
    	        	$(".vehicleLevelTd").html("舒适型");
    	        }
    	        else if(data.vehicleLevelId == 3) {
    	        	$(".vehicleLevelTd").html("商务型");
    	        }
    	        else if(vehicleLevelId == 4) {
    	        	$(".vehicleLevelTd").html("豪华型");
    	        }
    	        else {
    	        	$(".vehicleLevelTd").html("无");
    	        }
    	        var sexdetail = data.sex;
    	        if(sexdetail == 1) {
    	        	$(".sexTd").html("男");
    	        }
    	        else if(sexdetail == 2) {
    	        	$(".sexTd").html("女");
    	        }
    	        else {
    	        	$(".sexTd").html(data.sex);
    	        }
    	        $(".telTd").html(data.telPhone);
    	        $(".idCardTd").html(data.idCard);
    	        $(".firstLicDateTd").html(data.jszLssueDate.substring(0,10));
    	        $(".endLicDateTd").html(data.jszValidityPeriod.substring(0,10));
    	        $(".yearsTd").html(data.driving);
    	        $(".licTypeTd").html(data.permittedType);
    	        $(".LicNoTd").html(data.jszFileNumber);
    	        $(".plateTd").html(data.lisencePlate);
    	        $(".carTypeTd").html(data.vehicleModel);
    	        $(".vehicleNoTd").html(data.vehicleNumber);
    	        $(".carNameTd").html(data.vehicleOwner);
    	        $(".registerDateTd").html(data.xszLssueDate.substring(0,10));
    	        
    	        //图片
    	        $(".idCardPositiveImage").attr("src", data.idCardPositiveImage);
    	        $(".idCardOppositeImage").attr("src", data.idCardOppositeImage);
    	        $(".vehicleImage").attr("src", data.vehicleImage);
    	        $(".jszImage").attr("src", data.jszImage);
    	        $(".jszCopyImage").attr("src", data.jszCopyImage);
    	        $(".xszImage").attr("src", data.xszImage);
    	        $(".xszCopyImage").attr("src", data.xszCopyImage);
    	        
    	        $("#myModalDetail").modal('show');
    		}
        	
        });
        
    } );
	
	
	//司机编辑
	$(document).on('click', '.btn-edit', function() {
		
		
		
		var data = table.row( $(this).parents('tr') ).data();
		var userId = data.userId;
		$.ajax({
        	
        	type: 'POST',
    		url: ctx+'/driver/v1/dvdetail',
    		dataType: 'json',
    		data: {
    			suid: userId
    		},
    		success: function(data) {
    			console.log(data);
    			wholeautype = data.authType;
				//3:出租车  2:专车
				if(wholeautype == 2) {
					$(".workLicenseNumberThedit").hide();
					$(".workLicenseNumberTdedit").hide();
					$(".workLicenseImageDivEdit").hide();
//					$(".workLicenseImageDiv").hide();
				}
				if(wholeautype == 3) {
					$(".workLicenseNumberThedit").show();
					$(".workLicenseNumberTdedit").show();
					$(".workLicenseNumberTdedit input").val(data.workLicenseNumber);
					$(".workLicenseImageDivEdit").show();
					$(".imgBox8 img").attr("src", data.workLicenseImage);
					newimg8 = $('.imgBox8 img').attr('src').substring(56,100);
	    			$(".imgBox8").attr("data-value",newimg8);
	    			
				}
				
    			newspecialAuthInfoId = data.specialAuthInfoId;
    			newsuId = data.suId;
    			newuserId = data.userId;
    			newuvId = data.uvId;
    			newvaId = data.vaId;
    	        $(".provinceEditSelect").find("option[data-value='"+data.provice_name+"']").attr("selected",true);
//    	        $(".cityEditSelect").find("option[data-value='"+data.cityName+"']").attr("selected",true);
    	        $(".companyEditSelect").find("option[data-value='"+data.organizationName+"']").attr("selected", true);
    	        $.ajax({
    	        	type: 'POST',
    	    		url: ctx+'/proandcity/v1/city',
    	    		dataType: 'json',
    	    		data: {
    	    			proviceId: data.provinceId
    	    		},
    	    		success: function(data1) {
    	    			var cityTpl = document.getElementById("cityEditSelectTpl").innerHTML;
    	    			var cityhtml = juicer(cityTpl, data1);
    	    			$(".cityEditSelect").html(cityhtml);
    	    			$(".cityEditSelect").find("option[data-value='"+data.cityId+"']").attr("selected",true);
    	    		}
    	    	});
    	        $('.vehicleLevelEditTd').find("option[value="+data.vehicleLevelId+"]").attr("selected", true);
    	        $(".nameEditTd input").val(data.trueName);
    	        $(".sexEditTd").find("input[value='"+data.sex+"']").attr('checked',true);
    	        $(".telEditTd input").val(data.telPhone);
    	        $(".idCardEditTd input").val(data.idCard);
    	        $(".firstLicDateEditTd input").val(data.jszLssueDate.substring(0,10));
    	        $(".endLicDateEditTd input").val(data.jszValidityPeriod.substring(0,10));
    	        $(".yearsEditTd").html(data.driving);
//    	        $(".licTypeEditTd").html(data.permittedType);
    	        $(".licTypeEditTd").find("option[data-value='"+data.permittedType+"']").attr('selected',true);
    	        $(".LicNoEditTd input").val(data.jszFileNumber);
    	        $(".plateEditTd input").val(data.lisencePlate);
    	        //车型比较复杂后台会返回branchName和modelName   	        
    	        $('.carTypeEditTd .carBrandSelect').find("option[data-value='"+data.vehicleType+"']").attr("selected", true);
    	        var editBranchId = $('.carTypeEditTd .carBrandSelect').find("option[data-value='"+data.vehicleType+"']").attr("value");
    	        $.ajax({
    	    		type: 'POST',
    	    		url: ctx+'/cartype/v1/model',
    	    		dataType: 'json',
    	    		data: {
    	    			id: editBranchId
    	    		},
    	    		success: function(data1) {
    	    			var carModels = {};
    	    			carModels.list = data1;
    	    			var carModelTpl = document.getElementById("carModelSelectTpl").innerHTML;
    	    			var carModelhtml = juicer(carModelTpl, carModels);
    	    			$(".carModelSelect").html(carModelhtml);
    	    			$('.carTypeEditTd .carModelSelect').find("option[data-value='"+data.vehicleModel+"']").attr("selected", true);
    	    		}
    	    	});
    	        
    	        
    	        $(".vehicleNoEditTd input").val(data.vehicleNumber);
    	        $(".carNameEditTd").html(data.vehicleOwner);
    	        $(".registerDateEditTd input").val(data.xszLssueDate.substring(0,10));
    	        
    	        //图片
    	        $(".imgBox1 img").attr("src", data.idCardPositiveImage);
    	        $(".imgBox2 img").attr("src", data.idCardOppositeImage);
    	        $(".imgBox3 img").attr("src", data.vehicleImage);
    	        $(".imgBox4 img").attr("src", data.jszImage);
    	        $(".imgBox5 img").attr("src", data.jszCopyImage);
    	        $(".imgBox6 img").attr("src", data.xszImage);
    	        $(".imgBox7 img").attr("src", data.xszCopyImage);
    	        
    	        //将阿里云的图片截取后面字段存在imgBox的data-value属性中
    	        newimg1 = $('.imgBox1 img').attr('src').substring(56,100);
    			$(".imgBox1").attr("data-value",newimg1);
    			newimg2 = $('.imgBox2 img').attr('src').substring(56,100);
    			$(".imgBox2").attr("data-value",newimg2);
    			newimg3 = $('.imgBox3 img').attr('src').substring(56,100);
    			$(".imgBox3").attr("data-value",newimg3);
    			newimg4 = $('.imgBox4 img').attr('src').substring(56,100);
    			$(".imgBox4").attr("data-value",newimg4);
    			newimg5 = $('.imgBox5 img').attr('src').substring(56,100);
    			$(".imgBox5").attr("data-value",newimg5);
    			newimg6 = $('.imgBox6 img').attr('src').substring(56,100);
    			$(".imgBox6").attr("data-value",newimg6);
    			newimg7 = $('.imgBox7 img').attr('src').substring(56,100);
    			$(".imgBox7").attr("data-value",newimg7);
    	        
    	        $("#myModalEdit").modal('show');
    		}
        	
        });
        
        
		
	});
	
	$("#editdriverform").
	bootstrapValidator({
		message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
        	editdrivername: {//姓名
                validators: {
                    notEmpty: {
                        message: '不能为空'
                    },
                    regexp: {
                    	regexp: /^[a-zA-Z\u4e00-\u9fa5]+$/,
                    	message: '只能输入汉字或英文姓名'
                    }
                }
            },
            editdrivertel: {//手机号码
                validators: {
                    notEmpty: {
                        message: '不能为空'
                    },
                    regexp: {
                    	regexp: /^((\+?86)|(\(\+86\)))?(13[012356789][0-9]{8}|15[012356789][0-9]{8}|18[02356789][0-9]{8}|147[0-9]{8}|1349[0-9]{7})$/,
                    	message: '请输入正确格式手机号码'
                    }
                }
            },
            editdriveridcard: {//身份证号
            	validators: {
            		notEmpty: {
            			message: '不能为空'
            		},
            		regexp: {
            			regexp: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/,
            			message: '请输入正确身份证号码'
            		}
            	}
            },
            editdriverlicno: {//驾驶证档案编号
            	validators: {
                    notEmpty: {
                        message: '不能为空'
                    },
                    regexp: {
                    	regexp: /^\d{12}$/,
                    	message: '12位数字'
                    }
                }
            },
            editdriverplate: {//车牌号
            	validators: {
            		notEmpty: {
            			message: '不能为空'
            		},
            		regexp: {
            			regexp: /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/,
            			message: '简称+大写英文字母+5位数字'
            		}
            	}
            },
            editdrivervehicleno: {//车架号
            	validators: {
            		notEmpty: {
            			message: '不能为空'
            		},
            		regexp: {
            			regexp: /^[a-zA-Z0-9]{17}$/,
            			message: '大写字母和数字混合，共17位'
            		}
            	}
            },
            editdriverworknumber: {//从业资格证号
            	validators: {
            		notEmpty: {
            			message: '不能为空'
            		},
            		regexp: {
            			regexp: /^\d{19}$/,
            			message: '19位数字'
            		}
            	}
            }
            
            
        }
	});
	
	
	//编辑之后保存
	$('.edit-save').on('click', function() {
		
		confirmEditDriver();
		
	});
	
	
	
	//禁用
	$(document).on( 'click', '.btn-forbid', function () {
        var data = table.row( $(this).parents('tr') ).data();
        console.log(data);
        var suId = data.specialAuthInfoId;
        var isDel = data.is_del;
        console.log(suId + ',' + isDel);
        $.ajax({
        	type: 'POST',
        	url: ctx+'/driver/v1/dvmodify',
        	dataType: 'json',
        	data: {
        		suId: suId,
        		isdel: 2
        	},
        	success: function(data) {
        		console.log('禁用成功');
        	}
        });
	});
	
	
	//点击编辑模态框图片查看原图
	$('#myModalEdit img').on('click', function() {
		console.log($(this).attr('src'));
		var bigSrc = $(this).attr('src');
		$('.bgmodal img').attr('src',bigSrc);
		$('.bg').fadeIn(200);
		$('.bgmodal').fadeIn(400);
	});
	
	
	
	//点击详情模态框图片查看原图
	$('#myModalDetail img').on('click', function() {
		console.log($(this).attr('src'));
		var bigSrc = $(this).attr('src');
		var bigTitle = $(this).siblings('h4').text();
		$('.bgmodal img').attr('src',bigSrc);
		$('.bg').fadeIn(200);
		$('.bgmodal').fadeIn(400);
	});
	$('.bg').on('click', function() {
		$('.bg').fadeOut(200);
		$('.bgmodal').fadeOut(200);
	});
	
	//点击旋转图片
	var current = 0;
	$('.rotate-icon').on('click', function() {
//		alert($(this).siblings("img").attr('src'));
		var roteteImgSrc = $(this).siblings("img").attr('src');
		current = (current+90)%360;
		$(this).siblings("img").css({'transform': 'rotate('+current+'deg)'});
	});
	$('.bgmodal img').on('click', function() {
//		alert($(this).siblings("img").attr('src'));
//		var roteteImgSrc = $(this).siblings("img").attr('src');
		current = (current+90)%360;
		$(this).css({'transform': 'rotate('+current+'deg)'});
	});
	
	
	//图片上传
	/*$(".upload-btn").on("click", function() {
		var n = $(this).attr("data-value");
		var srcImage = $(this).siblings("div").find("img").attr("src");
		uploadImage(srcImage, n);
	});*/
	
	
	function uploadImage(srcImage, n) {
		$.ajax({
 			type: 'POST',
 			url: ctx+'/driver/v1/upimage',
 			dataType: 'json',
 			data: {
 				srcImage: srcImage
 			},
 			beforeSend:function(){
 				$(".progress-bar" + n).attr("aria-valuenow", '0');
 				$(".progress-bar" + n).css({width: '45%',color: '#000'});
// 				$(".upbtn"+n).html('上传中,请耐心等待');
 				$(".progress-bar" + n).html('上传中..');
 			},
 			success: function(data) {
// 				$(".upbtn"+n).html('上传成功');
 				$(".imgBox"+n).attr("data-value",data);
 				$(".progress-bar" + n).attr("aria-valuenow", '100');
 				$(".progress-bar" + n).css({width: '100%'});
 				$(".progress-bar" + n).html('上传成功');
 			}
		});
	}
	
	
	function readURL(input,n) {
	
		var fileName = $(".imgInp"+n).val();
		var suffixIndex=fileName.lastIndexOf(".");  
		var suffix=fileName.substring(suffixIndex+1).toUpperCase();  
		if(suffix!="BMP"&&suffix!="JPG"&&suffix!="JPEG"&&suffix!="PNG"&&suffix!="GIF"){  
			alert("请上传图片");
		}
		else {
			if (input.files && input.files[0]) {
	           var reader = new FileReader();
	           reader.onload = function (e) {
	               $('#blah'+n).attr('src', e.target.result);
	               uploadImage($('#blah'+n).attr('src'), n);     
	           }
	           reader.readAsDataURL(input.files[0]);
	       }
		}
		
       
    }

    $(".imgInp").change(function(){
    	readURL(this,$(this).attr("data-value"));
    });

    
    //获取省份
    function getProvince() {
    	$.ajax({
        	type: 'POST',
    		url: ctx+'/proandcity/v1/pro',
    		dataType: 'json',
    		success: function(data) {
    			
    			var provinceTpl = document.getElementById("provinceSelectTpl").innerHTML;
    			var provincehtml = juicer(provinceTpl, data);
    			var newprovincehtml = "<option value=''>全部</option>" + provincehtml;
    			$(".provinceSelect").html(newprovincehtml);
    			
    		}
    	});
    }
    
	
    //根据省份获取城市(可以传空，代表全部)
    function getCity(provinceId) {
    	$.ajax({
        	type: 'POST',
    		url: ctx+'/proandcity/v1/city',
    		dataType: 'json',
    		data: {
    			proviceId: provinceId
    		},
    		success: function(data) {
    			var cityTpl = document.getElementById("citySelectTpl").innerHTML;
    			var cityhtml = juicer(cityTpl, data);
    			var newcityhtml = "<option value=''>全部</option>" + cityhtml;
    			$(".citySelect").html(newcityhtml);
    			
    		}
    	});
    }
    
    
    //根据省份和城市获取公司(可以传空，代表全部)
    function getCompany(provinceId,cityId) {
    	$.ajax({
    		type: 'POST',
    		url: ctx+'/sys/v1/organization/listId',
    		dataType: 'json',
    		data: {
    			proviceId: provinceId,
    			sysCityId: cityId
    		},
    		success: function(data) {
    			var company = {};
    			company.list = data;
    			var companyTpl = document.getElementById("companySelectTpl").innerHTML;
    			var companyhtml = juicer(companyTpl, company);
    			var newcompanyhtml = "<option value=''>全部</option>" + companyhtml;
    			$(".companySelect").html(newcompanyhtml);
    		}
    	});
    }
    
    //编辑获取省份
    function editgetProvince() {
    	$.ajax({
        	type: 'POST',
    		url: ctx+'/proandcity/v1/pro',
    		dataType: 'json',
    		success: function(data) {
    			var provinceTpl = document.getElementById("provinceEditSelectTpl").innerHTML;
    			var provincehtml = juicer(provinceTpl, data);
    			$(".provinceEditSelect").html(provincehtml);
    		}
    	});
    }
    //编辑获取城市
    function editgetCity(provinceId) {
    	$.ajax({
        	type: 'POST',
    		url: ctx+'/proandcity/v1/city',
    		dataType: 'json',
    		data: {
    			proviceId: provinceId
    		},
    		success: function(data) {
    			var cityTpl = document.getElementById("cityEditSelectTpl").innerHTML;
    			var cityhtml = juicer(cityTpl, data);
    			$(".cityEditSelect").html(cityhtml);
    			
    		}
    	});
    }
    //编辑获取公司
    function editgetCompany(provinceId,cityId) {
    	$.ajax({
    		type: 'POST',
    		url: ctx+'/sys/v1/organization/listId',
    		dataType: 'json',
    		data: {
    			proviceId: provinceId,
    			sysCityId: cityId
    		},
    		success: function(data) {
    			var company = {};
    			company.list = data;
    			var companyTpl = document.getElementById("companyEditSelectTpl").innerHTML;
    			var companyhtml = juicer(companyTpl, company);
    			$(".companyEditSelect").html(companyhtml);
    		}
    	});
    }
    //获取车辆品牌
    function getCarBrand() {
    	$.ajax({
    		type: 'POST',
    		url: ctx+'/cartype/v1/brand',
    		dataType: 'json',
    		success: function(data) {
    			var carBrands = {};
    			carBrands.list = data;
    			var carBrandTpl = document.getElementById("carBrandSelectTpl").innerHTML;
    			var carBrandhtml = juicer(carBrandTpl, carBrands);
    			$(".carBrandSelect").html(carBrandhtml);
    		}
    	});
    }
    
    //获取车辆类型
    function getCarModel(carBrandId) {
    	$.ajax({
    		type: 'POST',
    		url: ctx+'/cartype/v1/model',
    		dataType: 'json',
    		data: {
    			id: carBrandId
    		},
    		success: function(data) {
    			var carModels = {};
    			carModels.list = data;
    			var carModelTpl = document.getElementById("carModelSelectTpl").innerHTML;
    			var carModelhtml = juicer(carModelTpl, carModels);
    			$(".carModelSelect").html(carModelhtml);
    		}
    	});
    }
    
    //获取非超级管理员用户所能访问的公司列表
    function getCompanyByOtherUser() {
    	$.ajax({
    		type: 'POST',
    		url: ctx+'/sys/v1/organization/organizationList',
    		dataType: 'json',
    		success: function(data) {
    			console.log(data);
    			var company = {};
    			company.list = data;
    			var companyTpl = document.getElementById("otherUserCompanySelectTpl").innerHTML;
    			var companyhtml = juicer(companyTpl, company);
    			var newcompanyhtml = "<option value=''>全部</option>" + companyhtml;
    			$(".otherUserCompanySelect").html(newcompanyhtml);
    		}
    	});
    }
    
    //确认编辑保存
    function confirmEditDriver() {
    	
    	$('#editdriverform').data('bootstrapValidator').validate();  
        if(!$('#editdriverform').data('bootstrapValidator').isValid()){  
            return ;  
        }
        
        var provinceId = $(".provinceEditSelect").find("option:selected").attr("value");//省份id
		var cityId = $(".cityEditSelect").find("option:selected").attr("value");//城市id
		var companyId = $(".companyEditSelect").find("option:selected").attr("value");//公司id
		var trueName = $(".nameEditTd input").val();//姓名
		var sex = $(".sexEditTd").find('input:checked').attr('value');//性别
		var telPhone = $(".telEditTd input").val();//手机号码
		var idCard = $(".idCardEditTd input").val();//身份证号码
		var jszLssueDate = $(".firstLicDateEditTd input").val();//初领驾驶证日期
		var jszValidityPeriod = $(".endLicDateEditTd input").val();//驾驶证截止日期
		var driving = $(".yearsEditTd").html();//驾龄
		var permittedType = $(".licTypeEditTd").find('option:selected').attr('data-value');//准驾车型
		var jszFileNumber = $(".LicNoEditTd input").val();//驾驶证档案编号
		var lisencePlate = $(".plateEditTd input").val();//车牌号
		var vehicleType = $('.carTypeEditTd .carBrandSelect').find("option:selected").attr("data-value");//车辆品牌
		var vehicleModel = $('.carTypeEditTd .carModelSelect').find("option:selected").attr("data-value");//车型
		var vehicleNumber = $(".vehicleNoEditTd input").val();//车架号
		var vehicleOwner = $(".carNameEditTd").html();//车辆所有人
		var xszLssueDate = $(".registerDateEditTd input").val(); //车辆注册日期
		var vehicleLevelId = $('.vehicleLevelEditTd').find("option:selected").attr("value");
		
		if(wholeautype == 2 || wholeautype == 1) {
			var workLicenseNumber = '';
			var workLicenseImage = '';
		}
		if(wholeautype == 3) {
			var workLicenseNumber = $(".workLicenseNumberTdedit input").val();
			var workLicenseImage = $(".imgBox8").attr("data-value");
		}
		
		if(jszLssueDate.length < 5) {
			alert("请选择初领驾驶证日期");
		}
		else if(jszValidityPeriod.length < 5) {
			alert("请选择驾驶证截止日期");
		}
		else if(xszLssueDate.length < 5) {
			alert("请选择车辆注册日期");
		}
		else if(new Date(jszLssueDate.replace(/\-/g, "\/")) > new Date(jszValidityPeriod.replace(/\-/g, "\/"))) {
 			alert("驾驶证初领日期不能大于驾驶证截止日期");
 		}
		else {
			$.ajax({
				type: 'POST',
				url:ctx+'/driver/v1/dvedit' ,
				dataType: 'json',
				data: {
					provice_id: provinceId,
					cityId: cityId,
					organizationId: companyId,
					trueName: trueName,
					sex: sex,
					telPhone: telPhone,
					idCard: idCard,
					jszLssueDate: jszLssueDate,
					jszValidityPeriod: jszValidityPeriod,
					driving: driving,
					permittedType: permittedType,
					jszFileNumber: jszFileNumber,
					lisencePlate: lisencePlate,
					vehicleType: vehicleType,
					vehicleModel: vehicleModel,
					vehicleNumber: vehicleNumber,
					vehicleOwner: vehicleOwner,
					xszLssueDate: xszLssueDate,
					specialAuthInfoId: newspecialAuthInfoId,
					suId: newsuId,
					userId: newuserId,
					uvId: newuvId,
					vaId: newvaId,
					idCardPositiveImage: $(".imgBox1").attr("data-value"),
					idCardOppositeImage: $(".imgBox2").attr("data-value"),
					vehicleImage: $(".imgBox3").attr("data-value"),
					jszImage: $(".imgBox4").attr("data-value"),
					jszCopyImage: $(".imgBox5").attr("data-value"),
					xszImage: $(".imgBox6").attr("data-value"),
					xszCopyImage: $(".imgBox7").attr("data-value"),
					workLicenseNumber: workLicenseNumber,
					workLicenseImage: workLicenseImage,
					vehicleLevelId: vehicleLevelId
				},
				success: function(data) {
					console.log(data);
					if(data == 'success') {
						alert("修改成功");
						window.location.reload();
					}
					else {
						alert("修改失败");
					}

				}
			});
		}
        
    }
    
    
});


